package com.bw.mapper;

import com.bw.domain.Role;
import com.bw.domain.User;
import com.bw.domain.UserMoney;
import lombok.Singular;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Select("select * from t_user where phone =#{phone}")
    User selectByPhone(String phone);


    List<User> list(User user);

    @Select("select * from t_user where id=#{id}")
    User get(String id);

    @Select("select id value ,role_name name from t_role")
    List<Role> listRole();

    @Update("update t_user set username=#{username}, password=#{password}, phone=#{phone}, idcard=#{idcard} ,header=#{header} where id=#{id}")
    int update(User user);

    @Delete("delete from t_user_role where user_id=#{id}")
    void deleteUserRole(Integer id);

    @Insert("insert into  t_user_role (user_id,role_id) values (#{userId},#{roleId})")
    void insertUserRole(@Param("userId") Integer userId,@Param("roleId") String roleId);

    @Select("select  id value ,role_name name from t_role  where id in (select role_id from  t_user_role a   where a.user_id=#{userId})")
    List<Role> listRoleByUserId(String userId);

    @Update("update t_user set balance =  balance + #{money} where id =#{userId}")
    void updateBalance(UserMoney userMoney);

    @Insert("insert into  t_user_money (user_id,money,create_time) values (#{userId},#{money},now())")
    void insertRecharge(UserMoney userMoney);

    List<UserMoney> listRecharge(UserMoney userMoney);

    @Update("update t_user set status=#{status} where id=#{id}")
    int updateStatus(User user);

    @Select("select * from t_user where id in (${ids})")
    List<User> listByIds(@Param("ids") String ids);
}
